package com.bltec.emergency.mapper;

import com.bltec.emergency.model.ResExperts;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ResExpertsMapper {
    //插入一条resExperts记录
    //id,name,sex,birth,category,type,event_type,department_id,position,tel,create_by,create_time,update_by,update_time,enable
    @Insert("insert into res_experts (name,sex,birth,category,type,event_type,department_id,position,tel," +
            "create_by,create_time,enable) " +
            "values(#{name},#{sex},#{birth},#{category},#{type},#{eventType},#{departmentId},#{position},#{tel},#{createBy},#{createTime},#{enable})")
    boolean insert(ResExperts resExperts);

    //通过name字段删除resExperts记录
    @Delete("delete from res_experts where name=#{name}")
    boolean deleteByName(String name);

    //通过id设置一条记录为不可用
    @Update("update res_experts set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update res_experts set name=#{name},sex=#{sex},birth=#{birth},category=#{category},type=#{type}," +
            "event_type=#{eventType},department_id=#{departmentId},position=#{position},tel=#{tel},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateResExpertsById(ResExperts resExperts);

    //查找符合name字段的记录
    @Select("select id,name,sex,birth,category,type,event_type,department_id,position,tel,create_by,create_time,update_by,update_time,enable " +
            "from res_experts where resExperts_name =#{name} and enable=1")
    ResExperts getResExpertsByName(String name);

    //查找符合name字段的记录的id
    @Select("select id from res_experts where resExperts_name =#{name} and enable=1")
    Long getIdByName(String name);

    //查找符合id字段的记录
    @Select("select id,name,sex,birth,category,type,event_type,department_id,position,tel,create_by,create_time,update_by,update_time,enable" +
            " from res_experts where id =#{id} and enable=1")
    ResExperts getResExpertsById(Long id);

    //查找所有记录
    @Select("select id,name,sex,birth,category,type,event_type,department_id,position,tel,create_by,create_time,update_by,update_time,enable" +
            " from res_experts where enable=1")
    List<ResExperts> selectAll();
}